package xyz.migle.sc.demo;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class DemoController002 {
    private static final Logger logger = LoggerFactory.getLogger(DemoController002.class);

    @GetMapping("/add")
    public int add(@RequestParam(name = "a", required = true) int a, @RequestParam(name = "b", required = true) int b) {
        logger.debug("a:{},b:{}",a,b);
        logger.info("a:{},b:{}",a,b);
        logger.warn("a:{},b:{}",a,b);
        logger.error("a:{},b:{}",a,b);
        //熔断测试:调用这个服务时会超时
//        try {
//            TimeUnit.MILLISECONDS.sleep(2000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        return a + b;
    }

    @GetMapping("/sub")
    public int sub(@RequestParam(name = "a", required = true) int a, @RequestParam(name = "b", required = true) int b) {
        logger.debug("a:{},b:{}",a,b);
        logger.info("a:{},b:{}",a,b);
        logger.warn("a:{},b:{}",a,b);
        logger.error("a:{},b:{}",a,b);
        return a - b;
    }
}
